jQuery(document).ready(function() {
	$('#kit-search-more').on('click', function() {
		$('.kit-search-mored').toggle();
	});
	
	var col = [ 
//	{
//	checkbox: 'checkbox'
//	},
//	{
//		title:'id',
//		field:'id',
//		align: 'center',
//		valign: 'middle',
//		visible: false
//	},
//	{
//		title:'唯一标识',
//		field:'uniqueId',
//		align: 'center',
//		valign: 'middle',
//		visible: false
//	},
	{
		title:'提交时间',
		field:'submissionTime',
		align: 'center',
		valign: 'middle'
	},
        {
            title:'外教',
            field:'teacherName',
            align: 'center',
            valign: 'middle'
        },
//	{
//		title:'外教id',
//		field:'teacherId',
//		align: 'center',
//		valign: 'middle',
//		visible: false
//	},
//	{
//		title:'外教名称',
//		field:'teacherName',
//		align: 'center',
//		valign: 'middle',
//		visible: false
//	},
	{
		title:'请假日期',
		field:'classDateStr',
		align: 'center',
		valign: 'middle'
        // formatter:function(value,row,index){
        //     // var newDate = new Date();
        //     // var oldTime = newDate.setTime(value);
        //     // var curTime = new Date(oldTime).format("yyyy-MM-dd");
        //     // return curTime;
        //
        //     var formattedDate = new Date(value);
        //     var d = formattedDate.getDate();
        //     var m = formattedDate.getMonth();
        //     m += 1;//JavaScript months are 0-11
        //     var y = formattedDate.getFullYear();
        //     return y + '-' + m +"-" + d;
        // }
	},
	// {
	// 	title:'Leave Time',
	// 	field:'classPeriod',
	// 	align: 'center',
	// 	valign: 'middle'
	// },
//	{
//		title:'请假课程名称',
//		field:'className',
//		align: 'center',
//		valign: 'middle'
//	},
//	{
//		title:'学生id',
//		field:'studentId',
//		align: 'center',
//		valign: 'middle'
//	},
//	{
//		title:'学生英文名',
//		field:'studentName',
//		align: 'center',
//		valign: 'middle'
//	},
	{
		title:'状态',
		// field:'state',
		align: 'center',
		valign: 'middle',
        formatter: function (value, row, index) {
            if (row.state == '0') {
                return '待审核';
            } else if (row.state == '1') {
                return '确认';
            } else if (row.state == '2') {
                return '-';
            }
        }
	},
	{
		title: '操作',
		align: 'center',
		valign: 'middle',
		formatter: function (value, row, index) {
			var id = value;
			return '<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="detail(\''+row.teacherId+'\',\''+row.submissionTime+'\')">查看</a>'+
                '<a href="javascript:;" class="layui-btn layui-btn-sm" onclick="updateStatus(\''+row.teacherId+'\',\''+row.submissionTime+'\')">审核</a>';
		}
	}];

	//------------------------------------------加载列表
	$('#_table').bootstrapTable({
		url:baseUrl+'/leaveRequests/list',
		'method': "GET",
		locale: 'zh-CN',
		detailView: false,
		sidePagination: "server", //服务端处理分页
		striped: true,//隔行变色
		undefinedText: "",
		pagination: true,
		singleSelect: false,
		pageSize: pageList[0],
		cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pageNumber: 1,
		pageList: pageList,
		search: true, //不显示 搜索框
		uniqueId: "uniqueId", //每一行的唯一标识，一般为主键列
		showColumns: true, //不显示下拉框（选择显示的列）
		showRefresh: true,
		undefinedText: '',
		columns: col,
		queryParams: function(params) {
			return {
				pageNum: this.pageNumber,
				pageSize: this.pageSize,
				sortOrder: params.order
			}
		},
		
	});

})

// 2018-10-7 chenbin: 新增请假
var insert = function() {
	parent.layer.open({
		title: 'My Leave Request',
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/Period_Used.html',
		btn: ['Submit', 'Cancel'],
		yes: function(index, layero) {
			var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			console.log(layero);
			$.ajax({
				url:baseUrl+ '/leaveRequests/saveLeaveInfo',
				type: 'POST',
				data: data,
				success: function(data) {
					alert(data.msg);
					parent.layer.close(index);
					$('#_table').bootstrapTable('refresh');
				}
			});
		},
		btn2: function(index, layero) {
			//按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}


// 2018-10-7 chenbin: 查看详情
var detail = function(teacherId,submissionTime) {
	var rows = $('#_table').bootstrapTable('getSelections');
	parent.layer.open({
		//				title: false,
		maxmin: true,
		type: 2,
		area: modalArea,
		content: './views/form/LeaveRequestDetail.html?submissionTime='+submissionTime+'&teacherId='+teacherId,
		btn: ['close'],
		yes: function(index, layero) {
            parent.layer.close(index);
            // var data = $(layero).find("iframe")[0].contentWindow.callback_save();
			// console.log(layero);
			// $.ajax({
			// 	url:baseUrl+ '/leaveRequests',
			// 	type: 'POST',
			// 	data: data,
			// 	success: function(data) {
			// 		alert(data.msg);
			// 		parent.layer.close(index);
			// 		$('#_table').bootstrapTable('refresh');
			// 	}
			// });
		},
		btn2: function(index, layero) {
            parent.layer.close(index);
            //按钮【按钮二】的回调
			console.log(layero);
			//return false 开启该代码可禁止点击该按钮关闭
		}
	});
}

function updateStatus(teacherId,submissionTime) {
    parent.layer.open({
        maxmin: true,
            type: 2,
            area: ['500px', '300px'],
            content:  baseUrl+'/views/form/LeaveRequrstStatus.html', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
            btn: ['保存', '取消'],
            yes: function(index, layero) {
                var data = $(layero).find("iframe")[0].contentWindow.callback_save();
                $.ajax({
                    type: "get",
                    url: baseUrl + "/leaveRequests/updateStatus?"+data+"&teacherId="+teacherId+"&submissionTime="+submissionTime,
                    success: function (data) {
                        parent.layer.close(index);
                        $('#_table').bootstrapTable('refresh');
                    }
                });
                parent.layer.close(index);
        },
        btn2: function (index, layero) {
            parent.layer.close(index);
        }
    });

    // parent.layer.open({
    //     title:'审核',
    //     type: 1,
    //     closeBtn: false,
    //     shift: 5,
    //     shadeClose: true,
    //     btn: ['提交','取消'],
    //     content: baseUrl+'/views/form/LeaveRequrstStatus.html', //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    //
    //     // "<div style='width:350px;'><div style='width:320px;margin-left: 3%;' class='form-group has-feedback'>" +
		// 	// "<select  id='shenhestate' name='shenhestate' >" +
		// 	// 	"<option value='0'>待审核</option>" +
		// 	// 	"<option value='1'>确认</option>" +
    //         // "</select>" +
		// 	// "</div>",
    //     // "<button style='margin-top:5%;' type='button' class='btn btn-block btn-success btn-lg' onclick='updateAward('"+purchaseCourseId+"')'>提交</button></div>",
    //     yes: function(index, layero) {
    //         var data = $(layero).find("iframe")[0].contentWindow.callback_save();
    //         $.ajax({
    //             type: "get",
    //             url: baseUrl + "/leaveRequests/updateStatus?"+data+"&teacherId="+teacherId+"&submissionTime="+submissionTime,
    //             success: function (data) {
    //                 parent.layer.close(index);
    //                 $('#_table').bootstrapTable('refresh');
    //             }
    //         });
    //         parent.layer.close(index);
    //     },
    //     btn2: function(index, layero) {
    //         parent.layer.close(index);
    //     }
    // });
}

